﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command.ApproveCommand;
using B.S.DataBase.MyRead.API.DTOs;
using MediatR;
using System.Collections.Generic;
using System.Drawing;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler.ApproveCommandHandler
{
    public class LeaveRecordCommandHandler: IRequestHandler<LeaveRecordCommand, APIResult<List<LeaveRecordDTO>>>
    {
        private readonly IBaseRepository<LeaveRecordModel> recorRepos;
        private readonly IBaseRepository<LeaveModel> leaveRepos;

        public LeaveRecordCommandHandler(IBaseRepository<LeaveRecordModel> recorRepos, IBaseRepository<LeaveModel> leaveRepos)
        {
            this.recorRepos = recorRepos;
            this.leaveRepos = leaveRepos;
        }

        public Task<APIResult<List<LeaveRecordDTO>>> Handle(LeaveRecordCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<LeaveRecordDTO>> result = new APIResult<List<LeaveRecordDTO>>();
            result.Code = APIEnum.查询成功;
            result.Msg= APIEnum.查询成功.ToString();
            var list = from a in recorRepos.GetAll().Result
                       join b in leaveRepos.GetAll().Result on a.LeaveId equals b.LeaveId
                       select new LeaveRecordDTO
                       {
                           LeaveId=b.LeaveId,
                           Reason=a.Reason,
                           RecordId=a.RecordId,

                       };
            result.data = list.ToList();
         return Task.FromResult(result);
        }
    }
}
